package api;
import java.io.Serializable; 
//import java.security.MessageDigest;
//import java.security.NoSuchAlgorithmException;
import java.util.ArrayList;

public class User implements Serializable {

	private static final long serialVersionUID = -7020619477594468968L;

	private String username;
	// private String password;
	private ArrayList<Message> messages;

        // Konstruktor
	public User(String name) {
		this.username = name;
		// this.password = passwordHash(password);
		this.messages = new ArrayList<Message>();
	}

        // Üzenetek megszerzése
	public final ArrayList<Message> getMessages() {
		return this.messages;
	}

        // Felhasználónév megszerzése
	public final String getUsername() {
		return this.username;
	}

	/*
	 * public boolean checkPassword(String pw) throws NoSuchAlgorithmException {
	 * return (this.password == passwordHash(pw)); }
	 */

        // Új üzenet alkotása
	public void newMessage(String topic, String text) {
		if (topic.length() > 0 && text.length() > 0) {
			this.messages.add(new Message(topic, text, this.username));
		}
	}

	/*
	 * private static String passwordHash(String password) throws
	 * NoSuchAlgorithmException {
	 * 
	 * MessageDigest md; StringBuffer sb = new StringBuffer(); md =
	 * MessageDigest.getInstance("MD5"); md.update(password.getBytes());
	 * 
	 * byte byteData[] = md.digest();
	 * 
	 * for (int i = 0; i < byteData.length; i++) {
	 * sb.append(Integer.toString((byteData[i] & 0xff) + 0x100, 16)
	 * .substring(1)); }
	 * 
	 * return sb.toString(); }
	 */

}
